<?php
/**
 * 地图
 * User: E 房cms www.fangcms.com
 * Date: 2015/1/20
 * Time: 10:51
 */
namespace Home\Controller;
use Org\Yike\FangCms;
class MapController extends CommonController{
    public function _initialize(){
        parent::_initialize();

    }

    public function index(){
        $type = I('get.type') ? I('get.type') : 'house';
        $hid = intval($_GET['hid']);
        if($type=='house'){
            if($hid){
                $seo = $house = M('house')->where(array('id'=>$hid,'status'=>1))->find();
                $this->house_data = M('house_data')->where(array('house_id'=>$house['id']))->find();
                $this->house = $house;
                $this->house_add = explode('|',$house['address']);
                $this->house_tel = explode('|',$house['tel']);
                $this->info = json_encode($house);
                $tpl = 'house_detail';
            }else{
                $this->area_list = M('house_cate')->where(array('status'=>1,'pid'=>0))->order('ordid desc')->select();
                $this->menu = getLinkMenuFor(array(3,6),1);
                $tpl = 'house_index';
            }
            $action_list = U('House/index');
            $action_map = U('Map/index',array('type'=>'house'));
        }

        if($type=='used'){
            if($hid){
                $seo = $used = M('used')->where(array('id'=>$hid,'status'=>1))->find();
                if($used['estate_id']){
                    $this->estate = M('estate')->where(array('id'=>$used['estate_id']))->find();
                    $seo['title'] = $this->estate['title'].$seo['title'];
                }
                $this->used = $used;
                $this->info = json_encode($used);
                $tpl = 'used_detail';
                $this->menu = getLinkMenuFor(array(17,10));
            }else{
                $this->area_list = M('area_cate')->where(array('status'=>1,'pid'=>0))->order('ordid desc')->select();
                $this->menu = getLinkMenuFor(array(24),1);
                $tpl = 'used_index';
            }
            $action_list = U('Used/index');
            $action_map = U('Map/index',array('type'=>'used'));
        }

        if($type=='rental'){
            if($hid){
                $seo = $rental = M('rental')->where(array('id'=>$hid,'status'=>1))->find();
                if($rental['estate_id']){
                    $this->estate = M('estate')->where(array('id'=>$rental['estate_id']))->find();
                    $seo['title'] = $this->estate['title'].$seo['title'];
                }
                $this->rental = $rental;
                $this->info = json_encode($rental);
                $tpl = 'rental_detail';
                $this->menu = getLinkMenuFor(array(17,10));
            }else{
                $this->area_list = M('area_cate')->where(array('status'=>1,'pid'=>0))->order('ordid desc')->select();
                $this->menu = getLinkMenuFor(array(24),1);
                $tpl = 'rental_index';
            }
            $action_list = U('Rental/index');
            $action_map = U('Map/index',array('type'=>'rental'));
        }

        if($type=='estate'){
            if($hid){
                $seo = $estate = M('estate')->where(array('id'=>$hid,'status'=>1))->find();
                if($estate['estate_id']){
                    $this->estate = M('estate')->where(array('id'=>$rental['estate_id']))->find();
                    $seo['title'] = $this->estate['title'].$seo['title'];
                }
                $this->estate = $estate;
                $this->info = json_encode($estate);
                $tpl = 'estate_detail';
                $this->menu = getLinkMenuFor(array(17,10));
                //二手房&出租房
                $where = array('status'=>1,'estate_id'=>$estate['id']);
                $this->used = M('used')->where($where)->order('id desc')->limit(6)->select();
                $this->rental = M('rental')->where($where)->order('id desc')->limit(6)->select();

            }else{
                $this->area_list = M('area_cate')->where(array('status'=>1,'pid'=>0))->order('ordid desc')->select();
                $this->menu = getLinkMenuFor(array(24),1);
                $tpl = 'estate_index';
            }
            $action_list = U('Rental/index');
            $action_map = U('Map/index',array('type'=>'rental'));
        }

        if(!$tpl){
            redirect('/');
        }
        $this->action_list = $action_list;
        $this->action_map = $action_map;
        $seo['seo_title'] = $seo['title'].'交通地图';
        $this->seoKey($seo);
        $this->display($tpl);
    }

}